<?php
include_once 'config/env.config.php';
include_once 'config/db.'.Env_Config.'.config.php';
include_once 'op/base.function.php';

$pic_table = "tbl_picture_solr";
$addition_table = "tbl_launch_picture_addition";

$solr_base_1 = 'http://10.30.11.80:8081/';
$solr_first_url_1 = $solr_base_1.'solr/db/dataimport?command=full-import';
$solr_then_url_1 = $solr_base_1.'solr/db/dataimport?command=delta-import';

$additionType = array('class','channel','tag','brand');

$skip = 1;
$loop = 60;
//$loop = 2700;
//$catid = 143;

$catid = '';
$affectNum = 0;

$options = array(PDO::ATTR_PERSISTENT=>FALSE);
$conn = new PDO('mysql:host='.dbHost.';dbname='.dbName, dbUser, dbPwd, $options);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec('SET NAMES ' . dbCharset);

while($skip <= $loop){
	$returnList = readElleRSS_pic($catid, $skip);
	
	if(is_array($returnList['rss'])){
		foreach ($returnList['rss'] as $value){
//			$select_sql = "select count(*) as num from $pic_table where pic_src='{$value['pic_src']}'";
//			$rs = $conn->query($select_sql);
//			$info = $rs->fetch();
//			if($info['num']>0)continue;
			
			$md5_url = md5($value['pic_src']);
			
			$sql = "replace into $pic_table (`md5_url`, `pic_src`, `tag`, `class`, `channel`, `brand`, `contentid`, `link`, `createTime`, `modified`) values ('{$md5_url}', '{$value['pic_src']}','{$value['tag']}','{$value['class']}','{$value['channel']}','{$value['brand']}', '{$value['contentid']}', '{$value['link']}' , '{$value['createTime']}', '{$value['modified']}')";				
			$affectNum = $conn->exec($sql);
		}
		
		// 导入solr数据
		file_get_contents($solr_then_url_1);
	}
	
	foreach ($returnList['addition'] as $key => $additionList){
		if(!in_array($key, $additionType))continue;
		if(is_array($additionList)){
			foreach ($additionList as $value) {
				if(empty($value) || $value=='')continue;
				$sql = "insert ignore into $addition_table (`name`, `type`) values ('{$value}','{$key}') ";				
				$numRows = $conn->exec($sql);
			}
		}
	}
	
	unset($returnList);
	$skip++;
}

echo 'affectNum:'.$affectNum."\n";

?>